/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var countPairs = function (nums, target) {
    nums.sort((a, b) => a - b)
    let left = 0
    let right = nums.length - 1
    let count = 0
    for (let i = 0; i < nums.length; i++) {
        left = i //为什么不重置right ？ 上一个left对应的数字比现有left对应的数组元素小，right后面的元素和旧left对应的元素和都不满足，与现有left更不满足
        while (left < right) {
            let sum = nums[left] + nums[right]
            if (sum < target) {
                count += right - left //left和right中间的数都满足条件
                break
            } else {
                right--
            }
        }
    }
    return count
};